import java.util.Stack;

public class text1 {
    //1.. 括号匹配
    //给定一个关于括号的字符串判断：这个字符串中括号字符是否匹配；
    public  static boolean KuoHao(String str){
        Stack<Character> stack=new Stack<>();
        for(int i=0;i<str.length();i++){
            char ch=str.charAt(i);
            if (ch == '(' || ch == '{' || ch =='[') {
                stack.push(ch);
            }else{
                if(stack.empty()){
                    return false;
                }
                char ch1=stack.peek();
                if(ch==')'&&ch1=='('||ch=='}'&&ch1=='{'||ch==']'&&ch1=='['){
                    stack.pop();
                }else{
                    return false;
                }
            }
        }
        if(!stack.empty()){
            return false;
        }
        return true;
    }
    public static void main1(String[] args){
        String str="({[]})";
        boolean ret=KuoHao(str);
        System.out.println(ret);
    }
    //. 逆波兰表达式求值
    public static int fib(String[] strs){
        Stack<Integer> stack=new Stack<>();
        for(String str:strs){
            if(!isoperation(str)){
                stack.push(Integer.parseInt(str));
            }else{
                int num2=stack.pop();
                int num1=stack.pop();
                switch(str){
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                }
            }
        }
        return stack.pop();
    }
    //判断字符数组中字符是否是操作符；
    public  static boolean isoperation(String str){
        if(str.equals("+")||str.equals("-")||str.equals("*")||str.equals("/")){
            return true;
        }
        return false;
    }
    public static void main2(String[] args){
        String[] strs={"1","2","3","+","*","4","-"};
        int ret=fib(strs);
        System.out.println(ret);
    }
    public static void main(String[] args){
        MyMinStack myMinStack=new MyMinStack();
        myMinStack.push(12);
        myMinStack.push(23);
        myMinStack.push(9);
        myMinStack.push(34);
        myMinStack.push(22);
        System.out.println(myMinStack.top());
        myMinStack.push(11);
        myMinStack.pop();
        System.out.println(myMinStack.top());
        System.out.println(myMinStack.getMin());
    }
}
